/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package devbureau.fstore.util;

import java.util.HashMap;
import java.util.Map;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

/**
 *
 * @author Vladimir
 */
public class ExcelStyles {
    public static final String TEST = "Test";
    public static final String ARYAL_CYR_12_PT_FONT = "Arial Cyr 12 pt font";
    public static final String ARYAL_CYR_12_PT_FONT_BOLD = "Arial Cyr 12 pt font bold";
    public static final String ARYAL_CYR_11_PT_FONT = "Arial Cyr 11 pt font";
    public static final String ARYAL_CYR_10_PT_FONT = "Arial Cyr 10 pt font";
    public static final String ARYAL_11_PT_FONT = "Arial 11 pt font";
    public static final String SENDER = "Sender";
    public static final String CUSTOMER = "Customer";
    public static final String ORDER_ID = "Order id";
    public static final String ORDER_DATE = "Order date";
    public static final String ORDER_TABLE_HEADER = "Order table header";
    public static final String ORDER_LINE_LABEL = "Order line label";
    public static final String ORDER_LINE_SIZE = "Order line size";
    public static final String ORDER_LINE_QUANTITY = "Order line quantity";
    public static final String ORDER_LINE_PRICE = "Order line price";
    public static final String ORDER_LINE_COST = "Order line cost";
    public static final String ORDER_TOTAL = "Order total";
    public static final String SENDER_SIGN = "Sender sign";
    public static final String CUSTOMER_SIGN = "Customer sign";


    private static Map<String, HSSFCellStyle> styles = null;
    
    public static Map<String, HSSFCellStyle> createStyles(HSSFWorkbook wb) {
        styles = new HashMap<String, HSSFCellStyle>();
        HSSFCellStyle style = null;

        //Arial cyr 12 pt
        HSSFFont arialCyr12 = wb.createFont();
        arialCyr12.setFontHeightInPoints((short)12);
        arialCyr12.setFontName("Arial Cyr");
        style = wb.createCellStyle();
        style.setFont(arialCyr12);
        styles.put(ARYAL_CYR_12_PT_FONT, style);

        //Arial cyr 12 pt Bold
        HSSFFont arialCyr12Bold = wb.createFont();
        arialCyr12Bold.setFontHeightInPoints((short)12);
        arialCyr12Bold.setFontName("Arial Cyr");
        arialCyr12Bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        style = wb.createCellStyle();
        style.setFont(arialCyr12Bold);
        styles.put(ARYAL_CYR_12_PT_FONT_BOLD, style);

        //Arial cyr 11 pt
        style = wb.createCellStyle();
        HSSFFont arialCyr11 = wb.createFont();
        arialCyr11.setFontHeightInPoints((short)11);
        arialCyr11.setFontName("Arial Cyr");
        style = wb.createCellStyle();
        style.setFont(arialCyr11);
        styles.put(ARYAL_CYR_11_PT_FONT, style);

        //Arial 11 pt
        style = wb.createCellStyle();
        HSSFFont arial11 = wb.createFont();
        arial11.setFontHeightInPoints((short)11);
        arial11.setFontName("Arial");
        style = wb.createCellStyle();
        style.setFont(arial11);
        styles.put(ARYAL_11_PT_FONT, style);

        //Arial cyr 10 pt
        style = wb.createCellStyle();
        HSSFFont arialCyr10 = wb.createFont();
        arialCyr10.setFontHeightInPoints((short)10);
        arialCyr10.setFontName("Arial Cyr");
        style = wb.createCellStyle();
        style.setFont(arialCyr10);
        styles.put(ARYAL_CYR_10_PT_FONT, style);

        //Получатель
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_CYR_12_PT_FONT));
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
        style.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        styles.put(CUSTOMER, style);

        //получил
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_CYR_10_PT_FONT));
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
        style.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        styles.put(CUSTOMER_SIGN, style);

        //от хх.хх.хххх г.
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_CYR_12_PT_FONT));
        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
        styles.put(ORDER_DATE, style);

        //накладная №
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_CYR_12_PT_FONT));
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
        styles.put(ORDER_ID, style);

        //сумма
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_11_PT_FONT));
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
        setBorders(style,
                   HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN,
                   HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN);
        styles.put(ORDER_LINE_COST, style);

        //наименование товара (название)
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_11_PT_FONT));
        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
        setBorders(style,
                   HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN,
                   HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN);
        style.setWrapText(true);
        styles.put(ORDER_LINE_LABEL, style);

        //цена
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_CYR_11_PT_FONT));
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
        setBorders(style,
                   HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN,
                   HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN);
        styles.put(ORDER_LINE_PRICE, style);

        //количесво
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_CYR_11_PT_FONT));
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
        setBorders(style,
                   HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN,
                   HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN);
        styles.put(ORDER_LINE_QUANTITY, style);

        //размер
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_11_PT_FONT));
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
        setBorders(style,
                   HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN,
                   HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN);
        styles.put(ORDER_LINE_SIZE, style);

        //шапка
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_CYR_12_PT_FONT_BOLD));
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        setBorders(style,
                   HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN,
                   HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN);
        styles.put(ORDER_TABLE_HEADER, style);

        //итого
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_CYR_12_PT_FONT));
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
        styles.put(ORDER_TOTAL, style);

        //Отправитель
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_CYR_12_PT_FONT));
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
        style.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        styles.put(SENDER, style);

        //отпустил
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get(ARYAL_CYR_10_PT_FONT));
        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
        style.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        styles.put(SENDER_SIGN, style);

        return styles;
    }

    private static HSSFCellStyle setBorders(HSSFCellStyle style, short left, short right, short top, short bottom) {
        style.setBorderTop(top);
        style.setBorderBottom(bottom);
        style.setBorderLeft(left);
        style.setBorderRight(right);
        return style;
    }
}
